package com.codingman.thymeleafdemo2;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.WebContext;

@WebServlet("/editform")
public class EditFormServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Map<String, String> sexList = new HashMap<String, String>();
		sexList.put("F", "Female");
		sexList.put("M", "Male");

		List<String> countryList = new ArrayList<String>();
		countryList.add("USA");
		countryList.add("China");
		countryList.add("England");

		WebContext ctx = new WebContext(request, response, request.getServletContext());
		ctx.setVariable("sexs", sexList);
		ctx.setVariable("countries", countryList);

		TemplateEngine engine = ThymeleafUtil.getTemplateEngine(request.getServletContext());
		engine.process("edit", ctx, response.getWriter());
	}
}
